
https://www.rdocumentation.org/packages/psych/versions/2.2.3/topics/mediate

# below works great and duplicates bootstrap result from PROCESS used in SPSS
# added mediate into R 3.6 via installing psych library 

install.packages("psych")

library(foreign)
library(psych)
x <- read.spss("U://My Documents//SUICIDES.sav")
x <- data.frame(x)
attach(x,2)
mod1 <- mediate(suicide ~ prestige + (educatio), data=x, n.iter=10)
summary(mod1)

# can add in other moderators in brackets, suicide is y variable (outcome) and prestige is x variable
# could add in interaction of moderator (m) and x variable as below augmenting existing dataframe

int <- prestige*educatio

xnew <- cbind(x,int)
attach(xnew,2)

mod2 <- mod1 <- mediate(suicide ~ prestige + (educatio) + (int), data=xnew, n.iter=10)
summary(mod2)